package 滑动窗口;

public class 翻转0 {

    public int longestOnes(int[] nums, int k) {
        int zero = 0,size = 0;
        for(int left=0,right =0;right<nums.length;right++){
            if(nums[right] == 0){
                zero++;
            }
            if(zero <= k){
                size = Math.max(size,right-left+1);
            }else{
                while(zero>k){
                    if(nums[left]==0){
                        left++;
                        zero--;
                    }else{
                        left++;
                    }
                }
            }
        }
        return size;
    }
    public int longestOnes1(int [] nums,int k){
        int ret = 0;
        for(int left= 0,right = 0,zero=0;right<nums.length;right++){
            if(nums[right] == 0) zero++; //进窗口
            while(zero>k){//判断
                if(nums[left++] == 0){
                    zero--;
                }
            }
            ret = Math.max(ret,right-left+1);
        }
        return ret ;
    }





    public static void main(String[] args) {
        int [] nums = {0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1};
        int target =3;





    }
}
